﻿using System;
using System.Windows.Media.Imaging;
using WeiboPlus.Models;

using WeiboPlus.Service;

namespace WeiboPlus.Service
{
    public abstract class SNSProvider
    {
        public SNSProvider()
        {
            Initialize();
        }

        protected virtual void Initialize()
        {
            this.Type = SNSProviderType.Unknow;
        }

        public OAuthSettings AuthSettings
        {
            get
            {
                return GetAuthSettings();
            }
        }

        public string ProviderName
        {
            get;
            set;
        }

        protected SNSProviderType type;
        public SNSProviderType Type
        {
            get { return type; }
            set { type = value; }
        }

        public T GetSerivce<T>() where T : IServiceFactory, new()
        {
            //return ;
            return new T();
        }
        BitmapImage iconImage;
        public BitmapImage IconImage
        {
            get
            {
                if (iconImage != null)
                    return iconImage;

                var uri = GetIconUrl();
                if (uri != null)
                {
                    iconImage = new BitmapImage(uri);
                    return iconImage;
                }
                else
                    return null;
            }
        }

        public IOAuthService AuthriozeService
        {
            get
            {
                return GetAuthriozeService();
            }
        }

        protected abstract IOAuthService GetAuthriozeService();

        protected abstract OAuthSettings GetAuthSettings();

        public abstract Uri GetIconUrl();

        public abstract bool IsSupported
        {
            get;
        }

        public SNSUser SupportUser
        {
            get;
            protected set;
        }
     
    }


}
